package com.qf.recharge.service.impl;

import com.qf.common.core.entity.Recharge;
import com.qf.common.core.utils.UserUtils;
import com.qf.recharge.mapper.RechargeMapper;
import com.qf.recharge.param.RechargeParam;
import com.qf.recharge.service.RechargeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * 2025/1/9
 */
@Service
public class RechargeServiceImpl implements RechargeService {

    @Resource
    private RechargeMapper rechargeMapper;

    @Override
    public void addRecharge(RechargeParam rechargeParam) {
        Integer uid = UserUtils.getUid();

        Recharge recharge = new Recharge();
        BeanUtils.copyProperties(rechargeParam, recharge);
        recharge.setAmount(rechargeParam.getAmount());
        recharge.setUid(uid);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        recharge.setOrderNo(sdf.format(new Date()));
        rechargeMapper.insert(recharge);
    }
}
